package com.zbkj.front.controller.login;


import com.zbkj.common.request.mszs.MszsMeituanLoginRequest;
import com.zbkj.service.thirdparty.login.request.*;
import com.zbkj.common.request.LoginRequest;
import com.zbkj.common.response.CommonResult;
import com.zbkj.service.thirdparty.login.response.LoginResponse;
import com.zbkj.service.service.sms.SmsService;
import com.zbkj.service.thirdparty.login.LoginFrontService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 移动端-用户登陆-controller控制器
 * @author lijie
 */
@Slf4j
@RestController("FrontLoginController")
@RequestMapping("api/front/login")
@Api(tags = "用户-登录注册")
public class LoginController {

    @Autowired
    private LoginFrontService loginService;

    @ApiOperation(value = "第三方登录-美团商家入驻(账号密码和手机号验证码注册登录)")
    @RequestMapping(value = "/loginMeituan", method = RequestMethod.POST)
    public CommonResult<LoginResponse> login(@RequestBody @Validated MszsMeituanLoginRequest loginRequest) {
        return CommonResult.success(loginService.loginMeituan(loginRequest));
    }

    @ApiOperation(value = "第三方登录-微信小程序授权登录(不需要强制绑定手机号)")
    @RequestMapping(value = "/loginWeixinXcxNotPhone", method = RequestMethod.POST)
    public CommonResult<LoginResponse> loginWeixinXcxNotPhone(@RequestBody @Validated WeixinXcxLoginRequest request){
        return CommonResult.success(loginService.loginWeixinXcxNotPhone(request));
    }

    @ApiOperation(value = "第三方登录-微信小程序授权登录(强制绑定手机号)")
    @RequestMapping(value = "/loginWeiXinXcx", method = RequestMethod.POST)
    public CommonResult<LoginResponse> loginWeiXinXcx(@RequestBody @Validated WeixinXcxLoginRequest request){
        return CommonResult.success(loginService.loginWeixinXcx(request));
    }

    @ApiOperation(value = "绑定手机号注册并登录-(获取微信用户绑定的手机号)")
    @RequestMapping(value = "/bindPhoneWeixin", method = RequestMethod.POST)
    public CommonResult<LoginResponse> bindPhoneWeixin(@RequestBody @Validated BindPhoneRegisterAndLoginWeiXinRequest request){
        return CommonResult.success(loginService.bindPhoneWeixin(request));
    }

    @ApiOperation(value = "绑定手机号注册并登录-(普通)")
    @RequestMapping(value = "/bindPhone", method = RequestMethod.POST)
    public CommonResult<LoginResponse> bindPhone(@RequestBody @Validated BindPhoneRegisterAndLoginRequest request){
        return CommonResult.success(loginService.bindPhone(request));
    }

    @ApiOperation(value = "手机号验证码登录-(获取微信用户绑定的手机号)")
    @RequestMapping(value = "/loginMobileCodeWeixin", method = RequestMethod.POST)
    public CommonResult<LoginResponse> loginMobileCodeWeixin(@RequestBody @Validated PhoneCodeLoginWeiXinRequest request){
        return CommonResult.success(loginService.loginMobileCodeWeixin(request));
    }

    @ApiOperation(value = "手机号验证码登录")
    @RequestMapping(value = "/loginMobileCode", method = RequestMethod.POST)
    public CommonResult<LoginResponse> loginPhoen(@RequestBody @Validated LoginMobileRequest loginRequest) {
        return CommonResult.success(loginService.loginPhoen(loginRequest));
    }

    @ApiOperation(value = "账号密码登录")
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public CommonResult<LoginResponse> login(@RequestBody @Validated AccountPwdLoginRequest loginRequest) {
        return CommonResult.success(loginService.loginAccountPwd(loginRequest));
    }

    @ApiOperation(value = "手机号密码登录")
    @RequestMapping(value = "/loginPhonePwd", method = RequestMethod.POST)
    public CommonResult<LoginResponse> loginPhonePwd(@RequestBody @Validated LoginRequest loginRequest) {
        return CommonResult.success(loginService.loginPhonePwd(loginRequest));
    }

    @ApiOperation(value = "退出登录")
    @RequestMapping(value = "/logout", method = RequestMethod.GET)
    public CommonResult<String> loginOut(HttpServletRequest request){
        loginService.loginOut(request);
        return CommonResult.success();
    }

}



